package Physics;

///////////////////////////////////////////
//Drag
//
//creates a drag force on the given object
///////////////////////////////////////////
class Drag extends ForceGenerator
{
	// holds the first-order coefficient ( k1 * v )
	double m_k1;
	
	// holds the second-order coefficient (k2 * v * v)
	double m_k2;
	
	// creates the FG and stores the data
	Drag(double k1, double k2)
	{
		m_k1=k1; 
		m_k2=k2;			
	}
	// applies the force to the object
	public void updateForce(RigidBody object, double dt)
	{
		// get the current velocity (call it force
		// since we'll apply this Vector as a force later)
		Vector3 force = object.getVelocity();
	
		// Calculate the total drag coefficient
		double dragCoeff = force.magnitude();
		dragCoeff = m_k1 * dragCoeff + m_k2 * dragCoeff * dragCoeff;
	
		// Calculate the final force and apply it
		// keep the same direction, but multiply it by the
		// total drag
		force.normalize();
		force.multiplyAndSet((float)-dragCoeff);
		object.applyForce(force);		
	}
}